package org.esprit.ocm.client.model.oca.datasource;

import java.util.ArrayList;
import java.util.List;

import org.esprit.ocm.client.model.oca.ClusterRecord;
import org.esprit.ocm.model.oca.ClusterOca;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.widgets.grid.ListGridRecord;

public class ClusterLocalDS extends DataSource {

	private static ClusterLocalDS	instance	= null;

	public static ClusterLocalDS getInstance(List<ClusterOca> lists) {
//		if (instance == null) {
			instance = new ClusterLocalDS("clusterLocalDS", lists);
//		}
		return instance;
	}

	public ClusterLocalDS(String id, List<ClusterOca> lists) {

//		setID(id);

		DataSourceTextField idField = new DataSourceTextField("id", "id");
		DataSourceTextField nameField = new DataSourceTextField("name", "name");
		
		setFields(idField, nameField);

		List<ListGridRecord> l = new ArrayList<ListGridRecord>();
		for (ClusterOca from : lists) {

			ClusterRecord to = new ClusterRecord();
			to.setId(from.getId());
			to.setName(from.getName());
			l.add(to);
		}

		setTestData(l.toArray(new ClusterRecord[0]));
		setClientOnly(true);
	}
}
